<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增产品二维码申请记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-qrcodeHistory-add">
            <input id="attributeId" name="attributeId" class="form-control" type="hidden">
            <input id="partsId" name="partsId" class="form-control" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">选择产品：</label>
                <div class="col-sm-8">
                    <input id="attributeName" name="attributeName" onclick="partsSelect()" class="form-control" type="text" placeholder="请选择要申请二维码的产品" readonly required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质保补助金金额：</label>
                <div class="col-sm-8">
                    <input id="payPrice" name="payPrice" class="form-control" type="text" readonly required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">申请数量：</label>
                <div class="col-sm-8">
                    <input name="applyNum" class="form-control" type="text" required>
                </div>
            </div>

        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="addQrcodeHistory()"><i class="fa fa-check"></i>确 定</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem1()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/qrcodeHistory"
        $("#form-qrcodeHistory-add").validate({
            focusCleanup: true
        });

        function addQrcodeHistory() {
            if ($.validate.form()) {
                var attributeId = $("input[name='attributeId']").val();
                var partsId = $("input[name='partsId']").val();
                var payPrice = $("input[name='payPrice']").val();
                var applyNum = $("input[name='applyNum']").val();
                var isFlag=false;
                var resultData;
                $.ajax({
                    type : "POST",
                    async: false,
                    url : prefix + "/add",
                    data : {
                        "attributeId": attributeId,
                        "partsId": partsId,
                        "payPrice": payPrice,
                        "applyNum": applyNum
                    },
                    error : function(request) {
                        $.modal.alertError("系统错误");
                    },
                    success : function(result) {
                        debugger;
                        resultData = result.data;
                        if(result.code == 0){
                            isFlag =true;
                            if(applyNum <=5000){
                                $.modal.loading("正在导出数据，请稍后...");
                                location.href = prefix + "/downloadExcelPrint?attributeId="+attributeId+"&qrCode="+resultData.qrcodeFirst+"00000000001"+"&applyNum="+applyNum;
                                // $.modal.confirm("已经申请成功，是否关闭当前页面？", function() {
                                //     $.modal.close();
                                // });
                                setTimeout(function () {
                                    layer.confirm("已经申请成功，是否关闭当前页面？", {
                                        icon: 3,
                                        title: "系统提示",
                                        btn: ['确认', '取消']
                                    }, function (index) {
                                        $.modal.close();
                                    },function(index){
                                        $.modal.closeLoading();
                                    })
                                }, 1000);
                            }else if(applyNum >5000 && applyNum <=10000){
                                // // 打开遮罩层
                                // $.modal.loading("正在导出数据，请稍后...");
                                // setTimeout(function () { location.href = prefix + "/downloadExcelPrint?attributeId="+attributeId+"&qrCode="+resultData.qrcodeFirst+"00000000001"+"&applyNum="+applyNum;
                                //     $.modal.confirm("已经申请成功，是否关闭当前页面？", function() {
                                //         $.modal.close();
                                //     }) }, 8000);
                                // // 打开遮罩层
                                // $.modal.loading("正在导出数据，请稍后...");

                                $.modal.loading("正在导出数据，请稍后...");
                                location.href = prefix + "/downloadExcelPrint?attributeId="+attributeId+"&qrCode="+resultData.qrcodeFirst+"00000000001"+"&applyNum="+applyNum;
                                setTimeout(function () {
                                    layer.confirm("已经申请成功，是否关闭当前页面？", {
                                        icon: 3,
                                        title: "系统提示",
                                        btn: ['确认', '取消']
                                    }, function (index) {
                                        $.modal.close();
                                    },function(index){
                                        $.modal.closeLoading();
                                    })
                                }, 3000);
                            }else {
                                // // 打开遮罩层
                                // $.modal.loading("正在导出数据，请稍后...");
                                // setTimeout(function () { location.href = prefix + "/downloadExcelPrint?attributeId="+attributeId+"&qrCode="+resultData.qrcodeFirst+"00000000001"+"&applyNum="+applyNum;
                                //     $.modal.confirm("已经申请成功，是否关闭当前页面？", function() {
                                //         $.modal.close();
                                //     }) }, 10000);
                                // // 打开遮罩层
                                // $.modal.loading("正在导出数据，请稍后...");

                                $.modal.loading("正在导出数据，请稍后...");
                                location.href = prefix + "/downloadExcelPrint?attributeId="+attributeId+"&qrCode="+resultData.qrcodeFirst+"00000000001"+"&applyNum="+applyNum;
                                setTimeout(function () {
                                    layer.confirm("已经申请成功，是否关闭当前页面？", {
                                        icon: 3,
                                        title: "系统提示",
                                        btn: ['确认', '取消']
                                    }, function (index) {
                                        $.modal.close();
                                    },function(index){
                                        $.modal.closeLoading();
                                    })
                                }, 6000);
                            }


                        }

                    }
                });
            }
        }


        function partsSelect() {
            var url = ctx+"zsyh/parts/partsTag/";
            layer.open({
                type: 2,
                area: ['800px', '500px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "选择产品",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

        function closeItem1() {
            $.modal.close();
        }

    </script>
</body>
</html>